package org.apache.lucene.ocean.util;

import java.util.Arrays;

/**
 * Pooled byte array objects.
 */
public class BytesPool extends ObjectArrayPool<byte[]> {
  private static BytesPool instance;
  
  public BytesPool(long evictTime) {
    super(evictTime);
  }
  
  public synchronized static BytesPool getInstance() {
    if (instance == null)
      instance = new BytesPool(DEFAULT_EVICT_TIME);
    return instance;
  }
  
  public byte[] newObject(int length) {
    return new byte[length];
  }
  
  public void returnObject(byte[] bytes) {
    Arrays.fill(bytes, (byte)0);
    ObjectArrays oa = getObjectArrays(bytes.length);
    oa.add(bytes);
  }
}
